﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using CCWin;

namespace weiqijiance
{
    public partial class TESTLI : Form
    {
        public string sshebei = "灯光";
        public mainform m_mainform;
        public string sdetid;
        public string revert = "";
        /// <summary>
        /// 结果变量
        /// </summary>

        public bool jcxjs = false;//检测线结束标识
        public bool ssxt = false;//采用双摄像头
        public bool bhwsx = false;//红外失效标识
        public float fguangqiangzuo;
        public float fguangqiangyou;

        public Thread t1;
        public string xianshineirong;
        public string businessId;
        public string jylsh;
        public string jyjgbh;
        public string jcxdh;
        public string jycs;
        public string jyxm;


        public string sdengzhi;//灯制
        public string sdengxing;//灯型
        public string sygtz;//远光调整
        public string sjgtz;//近光调整
        public string sweizhi;//位置
        public bool btdzttc;//调灯过程中途退出

        public bool bjczuodeng;//左灯检测
        public bool bjcyoudeng;//右灯检测
        public string sdengguangkaowei;//灯光仪器靠位

        public int iLIGHTGQ;//灯光光强
        public int iLIGQZuoYuan;//光强左远
        public float fLIZYPYZuoYuan;//左右偏移左远
        public float fLISXPYZuoYuan;//上下偏移左远
        public int iLIDGZuoYuan;//灯高左远

        public int iLIGQZuoJing;//光强左近
        public float fLIZYPYZuoJing;//左右偏移左近
        public float fLISXPYZuoJing;//上下偏移左近
        public int iLIDGZuoJing;//灯高左近

        public int iLIGQZuoFuYuan;//光强左副远
        public float fLIZYPYZuoFuYuan;//左右偏移左副远
        public float fLISXPYZuoFuYuan;//上下偏移左副远
        public int iLIDGZuoFuYuan;//灯高左副远



        public int iLIGQYouYuan;//光强右远
        public float fLIZYPYYouYuan;//左右偏移右远
        public float fLISXPYYouYuan;//上下偏移右远
        public int iLIDGYouYuan;//灯高右远

        public int iLIGQYouJing;//光强右近
        public float fLIZYPYYouJing;//左右偏移右近
        public float fLISXPYYouJing;//上下偏移右近
        public int iLIDGYouJing;//灯高右近

        public int iLIGQYouFuYuan;//光强右副远
        public float fLIZYPYYouFuYuan;//左右偏移右副远
        public float fLISXPYYouFuYuan;//上下偏移右副远
        public int iLIDGYouFuYuan;//灯高右副远


        public int iLIHWQ=-1;//红外前通道
        public int iLIHWH=-1;//红外前通道
        public int idengguangJZ = -1;//摩托车灯光夹子

        public bool jgpyfalse = false;//近光不评价
        public bool ygpyfalse = false;//远光不评价
        public bool needpy = false;//平台需要显示偏移
        public bool pyxz = false;//综检偏移限值是否采用安检标准
        public int xssj = 0;//显示时间
        public bool jmxz = false;
        public int gqsx = 0;
        public int gqxx = 0;
        public int idengguangtdz;//摩托车灯光光强
        public int idengguangcd;//摩托车灯光测量

        public bool bdwkongzhi = false;//是否定位延时控制
        public int idwy = 3000;//定位延时时间

        public bool[] bhongwaiqf = new bool[16] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };//红外是否取反
        public int[] ihongwaidwsj = new int[16] { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };//红外定位时间单位毫秒



        // /声明INI文件的写操作函数 WritePrivateProfileString()
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;

        灯光仪.libass objlibass = new 灯光仪.libass();
        声级计.nobass objnobass = new 声级计.nobass();
        public 控制流程.flowcrtl flowbass = new 控制流程.flowcrtl();
        public string stype;
        public TESTLI(int Width, int Height)
        {
            InitializeComponent();
            panel_Width = Width;
            panel_Height = Height;
            gettongdao();

            btdzttc = false;
            x = this.Width;
            y = this.Height;
            setTag(this);

            xinxixianshi.Text = "前照灯二灯检测";
           
        }
        bool bzjddzj = false;

        public void init()
        {
            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            string szkw = objini.ReadValue("灯光", "仪器左靠位").Trim();
            ygpyfalse = (objini.ReadValue("灯光", "安检远光偏移不评价").Trim() == "1") ? true : false;
            jgpyfalse = (objini.ReadValue("灯光", "安检近光偏移不评价").Trim() == "1") ? true : false;
            needpy = (objini.ReadValue("灯光", "平台需要显示偏移").Trim() == "1") ? true : false;
            pyxz = (objini.ReadValue("灯光", "综检偏移限值采用安检标准").Trim() == "1") ? true : false;

            bhwsx = (objini.ReadValue("灯光", "灯光后红外是否失效").Trim() == "1") ? true : false;

            jcxjs = (objini.ReadValue("灯光", "检测线结束设备").Trim() == "1") ? true : false;
            int.TryParse(objini.ReadValue("灯光", "信息显示时间").Trim(), out xssj);
            if (xssj < 10)
            {
                xssj = 3000;
            }

            sdengzhi = "二灯";
            if (flowbass.sjcbz.Contains("38900"))
            {
                sdengxing = "单测远光";
            }
            else
            {
                sdengxing = "远近光均测";
            }
            sygtz = "远光灯否需要调整";
            sjgtz = "近光灯否需要调整";
            sdengguangkaowei = (szkw == "1") ? "左" : "右";
            bzjddzj = objini.ReadValue("灯光", "只检单独综检").Trim().Contains("是") ? true : false;
            ssxt = (objini.ReadValue("灯光", "采用双摄像头").Trim() == "1") ? true : false;

            int.TryParse(objini.ReadValue("灯光", "开始延时").Trim(), out gqsx);
            if (gqsx < 10)
            {
                gqsx = 15000;
            }
            int.TryParse(objini.ReadValue("灯光", "结束延时").Trim(), out gqxx);
            if (gqxx < 10)
            {
                gqxx = 4000;
            }

            bdwkongzhi = objini.ReadValue("灯光", "定位控制").Trim().Contains("是") ? true : false;
            int.TryParse(objini.ReadValue("灯光", "定位时间").Trim(), out idwy);
            if (xssj < 10)
            {
                xssj = 3000;
            }

            if (idwy < 10)
            {
                idwy = 3000;
            }

        }
        public void start()
        {
            bianliangchushihua();
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();            
        }
        /// <summary>
        /// 变量初始化
        /// </summary>
        public void bianliangchushihua()
        {
            fguangqiangzuo = 0;
            fguangqiangyou = 0;

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

        }
        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            if (newy <= 0)
            {
                newy = 1;
            }
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件


        public void gettongdao()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
           
            for (int i = 0; i < 16; i++)
            {
                string shongwai = ReadValue("通道设置", string.Format(@"红外{0}", i + 1));
                if (shongwai.Contains("灯光到位前") || shongwai.Contains("摩托车遥控"))
                {
                    iLIHWQ = i;
                }
                if (shongwai.Contains("灯光到位后"))
                {
                    iLIHWH = i;
                }
              

                shongwai = ReadValue("通道设置", string.Format(@"红外定位时间{0}", i + 1));
                int.TryParse(shongwai, out ihongwaidwsj[i]);


                shongwai = ReadValue("通道设置", string.Format(@"红外是否取反{0}", i + 1));
                if (shongwai.Contains("是"))
                {
                    bhongwaiqf[i] = true;
                }
                else
                {
                    bhongwaiqf[i] = false;
                }
            }
            for (int i = 0; i < 16; i++)
            {

                string shongwai = ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("摩托车灯光夹子"))
                {
                    idengguangJZ = i;
                }
                if (shongwai.Contains("摩托车灯光测量"))
                {
                    idengguangcd = i;
                }
            }
            idengguangtdz = -1;
            for (int i = 0; i < 16; i++)
            {
                string sgetname = ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname == "摩托车光强")
                {
                    idengguangtdz = i;
                }
            }
           
        }


        private delegate void FlushClient();//代理
        private void xianshi()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xinxixianshi.Text = string.Format(@"{0}", xianshineirong);
            }
        }

        private void xianshizuo()
        {
            if (this.light_intensity.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshizuo);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.light_intensity.Visible = true;
                this.digitalGauge1.DigitCount = iLIGHTGQ.ToString("0").Length < 3 ? 3 : iLIGHTGQ.ToString("0").Length;
                this.digitalGauge1.Text = iLIGHTGQ.ToString("0");
               
            }
        }

      
        protected void thisclose()
        {

            this.Invoke(new Action(this.Close));  //使用委托关闭该窗体
        }

        public double DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            double dateDiff = 0;
            TimeSpan ts = DateTime1.Subtract(DateTime2).Duration();
            dateDiff = ts.Days * 60 * 60 * 60 * 1000 + ts.Hours * 60 * 60 * 1000 + ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
            return dateDiff;
        }

        public void WaitEvent(int lushu, int lushu2, bool bqufan, bool bqufan2, int stime, bool bzt = false)
        {
    
            DateTime dstart = DateTime.Now;
            bool firstzt = false;
            //;
            for (; ; )
            {
                if (flowbass.IsCancle())
                {
                    return;
                }
                bool bzhuangtai = m_mainform.DAC.bDIData[lushu];
                bool bzhuangtai2;
                if (lushu2<0)//fwj20200403
                {
                    bzhuangtai2 = false;
                }
                else
                {
                    bzhuangtai2 = m_mainform.DAC.bDIData[lushu2];
                }
                if (bqufan)
                {
                    bzhuangtai = !bzhuangtai;
                }
                if (bqufan2)
                {
                    bzhuangtai2 = !bzhuangtai2;
                }
              
                if (bzhuangtai)
                {
                    firstzt = true;
                    if (bzt)
                    {
                        if (bzhuangtai2)
                        {
                            flowbass.LedWrite(flowbass.sPlate, "后退", 1);
                            dstart = DateTime.Now;
                            continue;
                        }
                        else
                        {
                            flowbass.LedWrite(flowbass.sPlate, "停车", 1);
                        }
                        if (DateDiff(DateTime.Now, dstart) > stime)
                        {
                            break;
                        }
                    }
                    else
                    {
                        dstart = DateTime.Now;
                    }

                }
                else
                {
                    bzt = true;
                    if (firstzt)
                    {
                        flowbass.LedWrite(flowbass.sPlate, "前进", 1);
                    }
                    dstart = DateTime.Now;
                }
            }
        }
        float fshengji = 0;
        public void StratTestno()
        {
            if (!flowbass.bJCSJ)
                return;
            float fJGNO = 0;
            flowbass.LedWrite("准备检测声级", "3秒后按喇叭", 1);
            DateTime dstart = DateTime.Now;
            for (int i = 0; i < 3; i++)
            {
                flowbass.LedWrite("准备检测声级", string.Format("{0}秒后按喇叭", 3 - i), 1);
                while (true)
                {
                    Thread.Sleep(10);
                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                    if (m_mainform.DateDiff(DateTime.Now, dstart) > 1000)
                    {
                        dstart = DateTime.Now;
                        break;
                    }
                }
            }
            flowbass.LedWrite("开始检测声级", string.Format("按喇叭"), 1);
            dstart = DateTime.Now;
            for (; ; )
            {

                if (flowbass.IsCancle())
                {
                    return;
                }
                if (m_mainform.DateDiff(DateTime.Now, dstart) > 4000)
                {
                    xianshineirong = string.Format(@"声级检测完成");
                    xianshi();
                    break;
                }
                if (fJGNO < objnobass.fshengji)
                {
                    fJGNO = objnobass.fshengji;
                }
                fshengji = objnobass.fshengji;
                Thread.Sleep(300);
            }
            if (fJGNO==0)
            {
                fJGNO = m_mainform.getRandom(91, 114);
            }
            fshengji = fJGNO;
            bool bGood = true;
            if (fJGNO < 90 || fJGNO > 115)
            {
                bGood = false;
            }
            xianshineirong = string.Format("{0},{1}", fJGNO, bGood ? "合格" : "不合格");
            xianshi();
            flowbass.LedWrite(string.Format("{0}", fJGNO), string.Format("{0}", bGood ? "合格" : "不合格"), 1);
            Thread.Sleep(xssj);
            if (!bGood)
            {
                flowbass.getbuhge(flowbass.sDetectID, "SJ");
            }
            else
            {

                flowbass.sethege(flowbass.sDetectID, "SJ");
            }

            flowbass.AddData(flowbass.sDetectID, "DET_LB", "Detects_SJC", fJGNO);
            flowbass.AddData(flowbass.sDetectID, "DET_LAJL", "Detects_SJC", bGood?1:2);
            string jielun = "";
            jielun = string.Format(@"{0},{1},{2},{3}", "喇叭声压级(dB(A))", fshengji, "90～115", bGood ? "合格" : "不合格");
            Thread.Sleep(1000);
            flowbass.getProcessfinish(flowbass.sDetectID, "SJ");
        }       

        public void StratTest()
        {
            if (flowbass.bJCSJ)
            {
                xianshineirong = string.Format(@"准备检测声级");
                xianshi();
                flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                // 红外定位
                if (iLIHWQ > -1)//配置红外后才判断红外定位
                {

                    if (iLIHWH > -1)
                    {
                        if (bhwsx)
                        {
                            WaitEvent(iLIHWQ, -1, bhongwaiqf[iLIHWQ], false, ihongwaidwsj[iLIHWQ]);
                        }
                        else
                        {

                            WaitEvent(iLIHWQ, iLIHWH, bhongwaiqf[iLIHWQ], bhongwaiqf[iLIHWH], ihongwaidwsj[iLIHWQ]);
                        }
                    }
                    else
                    {
                        if (bhwsx)
                        {
                            WaitEvent(iLIHWQ, -1, bhongwaiqf[iLIHWQ], false, ihongwaidwsj[iLIHWQ]);
                        }
                    }

                }
                StratTestno();
            }
            灯光检测流程();
        }

        public void Thread1()
        {
            try
            {
                objlibass.bguiwei = false;
                StratTest();
                flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "灯光检测完成", flowbass.sDetectID);
                flowbass.Updatejcxhao(flowbass.objcarclass.jcxdh, flowbass.sDetectID);
                if (jcxjs)
                {
                    xianshineirong = "检测线完成";
                    flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "检测线完成", flowbass.sDetectID);
                    flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                    Thread.Sleep(xssj);
                }
                if (flowbass.LastProcessnew(int.Parse(flowbass.sDetectID)) && !flowbass.ifinish)
                {
                    flowbass.LedWrite("正在发送", "联网总结束", 1);
                    string slianwangfanhui = flowbass.objajlwbass.sendAJend(flowbass.jylsh, false, flowbass.bzj);
                    if (!(slianwangfanhui.Length > 0 && slianwangfanhui[0].ToString() == "1"))
                    {
                        flowbass.LedWrite("联网失败", slianwangfanhui, 1);
                    }
                    else
                    {
                        flowbass.LedWrite("发送完成", "", 1);
                        flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "检测线完成", flowbass.sDetectID);
                    }
                    Thread.Sleep(2000);
                }

                flowbass.LedWrite(flowbass.sgongwei, "", 1);
                xianshineirong = flowbass.sgongwei;
                xianshi();
                end();
            }
            catch (Exception ex)
            {
                //错误日记 记录到当天日期下目录中
                if (!(ex is System.Threading.ThreadAbortException))
                {
                    flowbass.LedWrite(flowbass.sPlate, "异常,停止检测", 1);
                    m_mainform.baocunriji("灯光", ex.Message.ToString());
                    m_mainform.SaveErrorLog("灯光检测流程", ex.Message.ToString());//problem
                }
            }
        }

        public int panel_Width;
        public int panel_Height;   

        private void TESTLI_Load(object sender, EventArgs e)
        {
            try
            {
                iniclass objini = new iniclass();
                string path = "";
                path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
                string path1 = string.Format(@"{0}", path);
                objini.Ini(path1);
                string sSetCom = objini.ReadValue("灯光", "灯光仪串口设置").Trim();
                stype = objini.ReadValue("灯光", "灯光仪型号").Trim();
                

                if (stype.Contains("MQD6A"))
                {
                    objlibass = new 灯光仪.MQD6A();
                }
                else if (stype.Contains("蕉岭综检6A"))
                {
                    objlibass = new 灯光仪.jiaoling6A();
                }
                else if (stype.Contains("MQD3A"))
                {
                    objlibass = new 灯光仪.MQD3A();
                }
                else if (stype.Contains("MQD1A"))
                {
                    objlibass = new 灯光仪.MQD1A();
                }
                else if (stype.Contains("MQD1C"))
                {
                    objlibass = new 灯光仪.MQD1C();
                }
                else if (stype.Contains("MQD1X"))
                {
                    objlibass = new 灯光仪.MQD1X();
                }
                else if (stype.Contains("NH6108"))
                {
                    objlibass = new 灯光仪.NH6108();
                }
                else if (stype.Contains("郴州MQDC"))
                {
                    objlibass = new 灯光仪.QDC_1C();
                }
                else if (stype.Contains("MQD6B"))
                {
                    objlibass = new 灯光仪.MQD6B();
                }
                if (sSetCom != "")
                {
                    objlibass.openCOM(sSetCom);
                }
                bzjddzj = objini.ReadValue("灯光", "只检单独综检").Trim().Contains("是") ? true : false;

                objnobass.init();

            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("灯光Load失败", ex.Message.ToString());//problem
                m_mainform.SaveErrorLog("灯光Load失败", ex.Message.ToString());//problem
            }

        }
      
        private void button2_Click(object sender, EventArgs e)
        {

            objlibass.sendLIcom(13);//仪器归位
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (flowbass.izhuangtai == 2)
                {
                    m_mainform.objyibiaobass.select(flowbass.sshebei);
                    m_mainform.bpanelshow = true;
                    m_mainform.showpanel();
                    flowbass.izhuangtai = 1;
                    //Thread tt = new Thread(end);
                    //tt.Start();
                    flowbass.IsReadyForStart();
                    bianliangchushihua();
                    t1 = new Thread(new ThreadStart(Thread1));
                    t1.Start();
                    //this.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("灯光打开窗体失败", ex.Message.ToString());
                m_mainform.SaveErrorLog("灯光打开窗体", ex.Message.ToString());//problem

            }
        }

        public void timerstart()
        {
            timer1.Enabled = true;
        }

        public void end()
        {          
            flowbass.izhuangtai = 0;
            flowbass.sendend("E", flowbass.sDetectID);
        }

        private void closeform()
        {
            if (this.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(closeform);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.Dispose();
                this.Close();
            }
        }

        private void 仪表设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            工位配置.LIsetting obj = new 工位配置.LIsetting();
            obj.ShowDialog();

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                m_mainform.sethongwai(toolStripLabel2, m_mainform.WaitEventZT(iLIHWQ, bhongwaiqf[iLIHWQ], ihongwaidwsj[iLIHWQ]));
                m_mainform.sethongwai(toolStripLabel4, m_mainform.WaitEventZT(iLIHWH, bhongwaiqf[iLIHWH], ihongwaidwsj[iLIHWH]));
            }
            catch
            { }
        }

        private void but_alone_Click(object sender, EventArgs e)
        {
            start();
        }

        private void xinxixianshi_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '·') 
            {
                e.Handled = true;
            }
        }

        private void 显示控件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowControls(true);
        }

        public void ShowControls(bool flag)
        {
            label1.Visible = flag;
            label2.Visible = flag;
            label3.Visible = flag;
            label4.Visible = flag;

            light_intensity.Visible = flag;
            light_verticality.Visible = flag;
            light_level.Visible = flag;
            light_height.Visible = flag;

            lblhongwai1.Visible = flag;
            lblhongwai2.Visible = flag;
            if (idengguangJZ > -1)
            {
                toolStripLabel8.Visible = flag;
                toolStripLabel7.Visible = flag;
            }

        }

        public void ShowButtons(bool flag)
        {
            but_alone.Visible = flag;
        }

        private void toolStripLabel8_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.LiftOne(true, (short)(idengguangJZ));
        }

        private void toolStripLabel7_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.LiftOne(false, (short)(idengguangJZ));
        }

        private void TESTLI_Shown(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);

            ShowButtons(false);
            this.BackgroundImage = Image.FromFile(@"./ico/灯光背景.jpg");
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
        }
        public void 灯光检测流程()
        {
            flowbass.STD_LI = 18000;
            if (flowbass.iQZDZ == 4)
            {
                flowbass.STD_LI = 15000;
            }
            flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "灯光检测开始", flowbass.sDetectID);
            if (!flowbass.bJCZZD && !flowbass.bJCYZD)
            {
                objlibass.bguiwei = true;
                xianshineirong = string.Format(@"灯光免检");
                xianshi();
                flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);

                if (flowbass.IsCancle())
                {
                    return;
                }
                return;
            }
            //if (m_mainform.web2.Length > 0 && (flowbass.cxjm(flowbass.sPlate, "H")))
            //{
            //    jmxz = true;
            //}
            flowbass.LedWrite(flowbass.sPlate, "前照灯检测", 1);
            //TESTNO tno = new TESTNO();


            // 红外定位
            if (iLIHWQ > -1)//配置红外后才判断红外定位
            {

                //if (iLIHWH > -1)
                //{
                //    //if (bhwsx)
                //    {
                //        WaitEvent(iLIHWQ, -1, bhongwaiqf[iLIHWQ], false, ihongwaidwsj[iLIHWQ],true);
                //    }
                //    //else
                //    //{

                WaitEvent(iLIHWQ, iLIHWH, bhongwaiqf[iLIHWQ], bhongwaiqf[iLIHWH], ihongwaidwsj[iLIHWQ],true);
                //    //}
                //}
                ////else
                ////{
                ////    if (bhwsx)
                ////    {
                //WaitEvent(iLIHWQ, -1, bhongwaiqf[iLIHWQ], false, ihongwaidwsj[iLIHWQ],true);
                //    }
                //}

            }
            if (flowbass.IsCancle())
            {
                return;
            }
            //if ((flowbass.bzj) || (flowbass.bsj))
            //{
            //    flowbass.sendpiczj("9999", flowbass.ilitongdao.ToString(), "dggw", "dggw");
            //}
            flowbass.LedWrite(flowbass.sPlate, "准备检测", 1);

            ///靠位
            if (sdengguangkaowei.Contains("左"))
            {
                objlibass.sendLIcom(1);
            }
            else
            {
                objlibass.sendLIcom(2);//
            }
            Thread.Sleep(1000);

            ///灯制
            if (flowbass.iQZDZ == 2)
            {
                objlibass.sendLIcom(3);
            }
            else if (flowbass.iQZDZ == 4)
            {
                objlibass.sendLIcom(4);
            }
            Thread.Sleep(1000);
            ///灯型
            //if (sdengxing.Contains("单测远光"))
            //{
            //    objlibass.sendLIcom(5);
            //}
            //else if (sdengxing.Contains("单测近光"))
            //{
            //    objlibass.sendLIcom(6);
            //}
            //else if (sdengxing.Contains("远近光均测"))
            //{
            objlibass.sendLIcom(7);
            //}
            Thread.Sleep(1000);
            /////远光调整

            ///位置
            //objlibass.sendLIcom(8);//先测远灯，后测近灯
            ////
            //Thread.Sleep(1000);

            objlibass.sendLIcom(14);//远光调整
            Thread.Sleep(1000);
            objlibass.sendLIcom(15);//近光调整
            Thread.Sleep(1000);

            //
            //发送指令
            DateTime dstartLD = DateTime.Now;

            //测量数据

            bjczuodeng = flowbass.bJCZZD;
            bjcyoudeng = flowbass.bJCYZD;
            if (sdengguangkaowei.Contains("左"))
            {
                if (bjczuodeng)
                {
                    DetectLightL();
                }
                if (flowbass.IsCancle())
                {
                    return;
                }

                //if (flowbass.bJCSJ && objnobass.bopen)
                //{
                //    StratTestno();
                //}


                if (flowbass.IsCancle())
                {
                    return;
                }
                Thread.Sleep(3000);
                //bjcyoudeng = true;
                if (bjcyoudeng)
                {
                    DetectLightR();
                }

                objlibass.sendLIcom(13);//仪器归位
            }
            else if (sdengguangkaowei.Contains("右"))
            {
                //bjcyoudeng = true;
                if (bjcyoudeng)
                {
                    DetectLightR();
                }

                if (flowbass.IsCancle())
                {
                    return;
                }
                //if (flowbass.bJCSJ && objnobass.bopen)
                //{
                //    StratTestno();
                //}


                if (flowbass.IsCancle())
                {
                    return;
                }
                Thread.Sleep(3000);
                if (bjczuodeng)
                {
                    DetectLightL();
                }
                objlibass.sendLIcom(13);//仪器归位

            }
            //if (jgpyfalse && ygpyfalse)
            //{
            //    flowbass.getguangqiang(iLIGQZuoYuan, iLIGQYouYuan);
            //}
        }
        public void DetectLightL()
        {

            flowbass.LedWrite("左主灯检测", "请开远光灯", 1);
            xianshineirong = string.Format(@"左主灯检测");
            xianshi();
            //发送测量指令
            objlibass.sendLIcom(9);//测量左灯

            // Thread.Sleep(1000);
            /*if (sdengguangkaowei.Contains("左"))
            {
                Thread.Sleep(3000);
                if (flowbass.bsj || flowbass.bnj)
                {
                        flowbass.objajlwbass.sendpic(flowbass.ilitongdao.ToString(), "0321", flowbass.objcarclass);//图片抓拍
                }

            }*/


            b调灯跳过 = false;
            objlibass.byuanguang = false;
            objlibass.byuanguangfudeng = false;
            objlibass.bjingguang = false;
            objlibass.bjcshibai = false;
            objlibass.b进入近光连续测量 = false;
            objlibass.b进入远光连续测量 = false;
            DateTime ddglc = DateTime.Now;

            while (true)
            {
                //Thread.Sleep(10);
                if (flowbass.IsCancle())
                {
                    return;
                }
                Thread.Sleep(10);
                if (objlibass.b进入远光连续测量)//结束触发
                {
                    break;
                }
                if (objlibass.bjcshibai)
                {
                    flowbass.LedWrite("左灯寻不到光", "左灯结束", 1);
                    xianshineirong = string.Format(@"左灯寻不到光");
                    xianshi();
                    return;
                }
            }
            flowbass.LedWrite("左主灯检测", "进入远光调整", 1);
            xianshineirong = string.Format(@"进入远光调整");
            xianshi();
            //if (sdengxing.Contains("远"))// 远光部分
            {
                while (true)
                {
                    Thread.Sleep(10);
                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                    Thread.Sleep(10);
                    iLIGQZuoYuan = objlibass.iLIGQ;//光强
                    fLIZYPYZuoYuan = objlibass.fLIZYPY;//左右偏移
                    fLISXPYZuoYuan = objlibass.fLISXPY;//上下偏移
                    iLIDGZuoYuan = objlibass.iLIDG;//灯高
                    if (objlibass.byuanguang)//结束触发
                    {
                        flowbass.LedWrite("左主灯检测", "远光检测完成", 1);
                        xianshineirong = string.Format(@"左主灯远光检测完成");
                        xianshi();
                        break;
                    }
                    if(b调灯跳过)
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("左灯寻不到光", "左灯结束", 1);
                        xianshineirong = string.Format(@"左灯寻不到光");
                        xianshi();
                        return;
                    }
                }
            }
            b调灯跳过 = false;
            Thread.Sleep(5000);

            /////副灯
            if (flowbass.iQZDZ == 4)
            {
                objlibass.byuanguang = false;
                objlibass.b进入远光连续测量 = false;
                objlibass.bjcshibai = false;
                while (true)
                {
                    //Thread.Sleep(10);
                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                    Thread.Sleep(10);
                    if (objlibass.b进入远光连续测量)//结束触发
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("左副灯寻不到光", "左副灯结束", 1);
                        xianshineirong = string.Format(@"左副灯寻不到光");
                        xianshi();
                        return;
                    }
                }
                flowbass.LedWrite("左副灯检测", "进入远光调整", 1);
                xianshineirong = string.Format(@"进入远光调整");
                xianshi();
                //if (sdengxing.Contains("远"))// 远光部分
                {
                    while (true)
                    {
                        Thread.Sleep(10);
                        if (flowbass.IsCancle())
                        {
                            return;
                        }
                        Thread.Sleep(10);
                        //iLIGQZuoYuan = objlibass.iLIGQ;//光强
                        //fLIZYPYZuoYuan = objlibass.fLIZYPY;//左右偏移
                        //fLISXPYZuoYuan = objlibass.fLISXPY;//上下偏移
                        //iLIDGZuoYuan = objlibass.iLIDG;//灯高

                        iLIGQZuoFuYuan = objlibass.iLIGQ;//光强
                        fLIZYPYZuoFuYuan = objlibass.fLIZYPY;//左右偏移
                        fLISXPYZuoFuYuan = objlibass.fLISXPY;//上下偏移
                        iLIDGZuoFuYuan = objlibass.iLIDG;//灯高
                        if (objlibass.byuanguang)//结束触发
                        {
                            flowbass.LedWrite("左副灯检测", "远光检测完成", 1);
                            xianshineirong = string.Format(@"左副灯远光检测完成");
                            xianshi();
                            break;
                        }
                        if (b调灯跳过)
                        {
                            break;
                        }
                        if (objlibass.bjcshibai)
                        {
                            flowbass.LedWrite("左副灯寻不到光", "左副灯结束", 1);
                            xianshineirong = string.Format(@"左副灯寻不到光");
                            xianshi();
                            return;
                        }
                    }
                }
                b调灯跳过 = false;
                //xianshineirong = string.Format(@"左副灯远光检测开副灯");
                //xianshi();
                //flowbass.LedWrite("开始检测副光", "请开副灯", 1);
                //while (true)
                //{

                //    if (flowbass.IsCancle())
                //    {
                //        return;
                //    }
                //    Thread.Sleep(10);
                //    iLIGQZuoFuYuan = objlibass.iLIGQ;//光强
                //    fLIZYPYZuoFuYuan = objlibass.fLIZYPY;//左右偏移
                //    fLISXPYZuoFuYuan = objlibass.fLISXPY;//上下偏移
                //    iLIDGZuoFuYuan = objlibass.iLIDG;//灯高


                //    if (ddglc.AddSeconds(120) < DateTime.Now)
                //        break;

                //    if (objlibass.byuanguangfudeng)//结束触发
                //    {
                //        objlibass.sjcdg = "左灯";
                //        xianshineirong = string.Format(@"左副灯检测完成");
                //        xianshi();
                //        break;
                //    }
                //    if (objlibass.bjcshibai)
                //        break;
                //}
            }
            //--------------------------------------------------------------------------------


            ///近光
            //if (sdengxing.Contains("近") && !flowbass.sjcbz.Contains("38900"))
            {

                if (flowbass.IsCancle())
                {
                    return;
                }
                xianshineirong = string.Format(@"左主灯近光检测开近光");
                xianshi();
                flowbass.LedWrite("开始检测近光", "请开近光灯", 1);
                while (true)
                {
                    Thread.Sleep(10);
                    if (objlibass.b进入近光连续测量)//结束触发
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("左灯寻不到光", "左灯结束", 1);
                        xianshineirong = string.Format(@"左灯寻不到光");
                        xianshi();
                        return;
                    }
                }
                flowbass.LedWrite("左主灯检测", "进入近光调整", 1);
                xianshineirong = string.Format(@"进入近光调整");
                xianshi();
                //--------------------------------------
                while (true)
                {
                    Thread.Sleep(10);
                    iLIGQZuoJing = objlibass.iLIGQ2;//光强
                    fLIZYPYZuoJing = objlibass.fLIZYPY2;//左右偏移
                    fLISXPYZuoJing = objlibass.fLISXPY2;//上下偏移
                    iLIDGZuoJing = objlibass.iLIDG2;//灯高


                    //if (ddglc.AddSeconds(120) < DateTime.Now)
                    //    break;
                    if (objlibass.bjingguang)//结束触发
                    {
                        objlibass.sjcdg = "左灯";
                        flowbass.LedWrite("左主灯检测", "左主灯检测完成", 1);
                        xianshineirong = string.Format(@"左主灯检测完成");
                        xianshi();
                        break;
                    }
                    if (b调灯跳过)
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("左灯寻不到光", "左灯结束", 1);
                        xianshineirong = string.Format(@"左灯寻不到光");
                        xianshi();
                        return;
                    }
                }
            }
            b调灯跳过 = false;

            if (flowbass.IsCancle())
            {
                objlibass.sendLIcom(13);//仪器归位
                return;
            }
            objlibass.bqushu = false;
            objlibass.sendLIcom(11);//取左主灯数据
            DateTime datejs = DateTime.Now;
            while (true)
            {

                if (flowbass.IsCancle())
                {
                    objlibass.sendLIcom(13);//仪器归位
                    return;
                }
                Thread.Sleep(10);
                if (objlibass.bqushu)
                {
                    break;
                }
                if (datejs.AddSeconds(20) < DateTime.Now)
                {
                    flowbass.LedWrite("左主灯检测完成", "仪器取数失败", 1);
                    return;
                }
            }
            flowbass.LedWrite("左主灯取数完成", "", 1);
            Thread.Sleep(xssj);
            iLIGQZuoYuan = objlibass.iLIGQ;//光强
            //if (jmxz)
            //{
            //    if (iLIGQZuoYuan < gqsx && iLIGQZuoYuan >= gqxx)
            //    {
            //        iLIGQZuoYuan = (iLIGQZuoYuan % 1000) + 15100;
            //    }
            //}
            fLIZYPYZuoYuan = objlibass.fLIZYPY;//左右偏移
            fLISXPYZuoYuan = objlibass.fLISXPY;//上下偏移
            iLIDGZuoYuan = objlibass.iLIDG;//灯高
            iLIGQZuoJing = objlibass.iLIGQ2;//光强
            fLIZYPYZuoJing = objlibass.fLIZYPY2;//左右偏移
            fLISXPYZuoJing = objlibass.fLISXPY2;//上下偏移
            iLIDGZuoJing = objlibass.iLIDG2;//灯高

            iLIGHTGQ = iLIGQZuoYuan;
            xianshizuo();
            //------------------------------------------------------------
            /////副灯
            if (flowbass.iQZDZ == 4)
            {
                objlibass.bqushu = false;
                objlibass.sendLIcom(17);//取左主灯数据
                datejs = DateTime.Now;
                while (true)
                {

                    if (flowbass.IsCancle())
                    {
                        objlibass.sendLIcom(13);//仪器归位
                        return;
                    }
                    Thread.Sleep(10);
                    if (objlibass.bqushu)
                    {
                        break;
                    }
                    if (datejs.AddSeconds(20) < DateTime.Now)
                    {
                        flowbass.LedWrite("左副灯", "仪器取数失败", 1);
                        return;
                    }
                }
                flowbass.LedWrite("左副灯取数完成", "", 1);
                Thread.Sleep(xssj);
                iLIGQZuoFuYuan = objlibass.iLIGQ;//光强
                fLIZYPYZuoFuYuan = objlibass.fLIZYPY;//左右偏移
                fLISXPYZuoFuYuan = objlibass.fLISXPY;//上下偏移
                iLIDGZuoFuYuan = objlibass.iLIDG;//灯高
            }
            //----------------------------------------------------------------
            double zwygczpy = 0;//左外远光垂直偏移

            double zwjgczpy = 0;//左外近光垂直偏移


            if (iLIDGZuoYuan == 0)
            {
                zwygczpy = 0;
            }
            else
            {
                zwygczpy = ((float)iLIDGZuoYuan + fLISXPYZuoYuan) / (float)iLIDGZuoYuan;
            }
            if (iLIDGZuoJing == 0)
            {
                zwjgczpy = 0;
            }
            else
            {
                zwjgczpy = ((float)iLIDGZuoJing + fLISXPYZuoJing) / (float)iLIDGZuoJing;
            }
            zwygczpy = Math.Round(zwygczpy, 2);
            zwjgczpy = Math.Round(zwjgczpy, 2);
            float znygczpy = 0;//左内远光垂直偏移

            bool bLlightGood = true;
            bool bBrightGood = true;
            bool bFVerGood = true;
            bool bNVerGood = true;

            bool b远光水平偏移判定 = true;
            bool b近光水平偏移判定 = true;


            #region
            //if (flowbass.bnj)
            {
                if (iLIGQZuoYuan < flowbass.STD_LI)
                {
                    bBrightGood = false;
                }


                if (zwygczpy < 0.8f || fLISXPYZuoYuan > 100)
                {
                    bFVerGood = false;
                }

                if (fLISXPYZuoJing < (iLIDGZuoJing > 1000 ? -350 : -300) || fLISXPYZuoJing > (iLIDGZuoJing > 1000 ? -100 : -50))
                {
                    bNVerGood = false;
                }


                if (fLIZYPYZuoYuan > 170 || fLIZYPYZuoYuan < -350)
                {
                    b远光水平偏移判定 = false;
                }

                if (fLIZYPYZuoJing > 170 || fLIZYPYZuoJing < -350)
                {
                    b近光水平偏移判定 = false;
                }

                if (bBrightGood && bFVerGood && bNVerGood && b远光水平偏移判定 && b近光水平偏移判定)
                {
                    bLlightGood = true;
                }
                else
                {
                    bLlightGood = false;
                }
            }
            #endregion

            bool bLlightfuGood = true;
            bool bBrightfuGood = true;
            bool bFVerfuGood = true;
            bool b远光副水平偏移判定 = true;
            double zfygczpy = 0;//左外远光垂直偏移
            if (flowbass.iQZDZ == 4)
            {
                if (iLIDGZuoFuYuan == 0)
                {
                    zfygczpy = 0;
                }
                else
                {
                    zfygczpy = ((float)iLIDGZuoFuYuan + fLISXPYZuoFuYuan) / (float)iLIDGZuoFuYuan;
                }
                zfygczpy = Math.Round(zfygczpy, 2);

                if (iLIGQZuoFuYuan < flowbass.STD_LI)
                {
                    bBrightfuGood = false;
                }
                if (zfygczpy < 0.8f || fLISXPYZuoFuYuan > 100)
                {
                    bFVerfuGood = false;
                }
                if (fLIZYPYZuoFuYuan > 170 || fLIZYPYZuoFuYuan < -350)
                {
                    b远光副水平偏移判定 = false;
                }
                if (bBrightfuGood && bFVerfuGood && b远光副水平偏移判定)
                {
                    bLlightfuGood = true;
                }
                else
                {
                    bLlightfuGood = false;
                }
                flowbass.AddData(flowbass.sDetectID, "DET_ZNDGQ", "Detects_SJA", iLIGQZuoFuYuan.ToString("0"));
                flowbass.AddData(flowbass.sDetectID, "DET_ZNYGCZPYL", "Detects_SJA", fLISXPYZuoFuYuan.ToString("0"));
                flowbass.AddData(flowbass.sDetectID, "DET_ZNYGCZPY", "Detects_SJA", zfygczpy.ToString("0.00"));
                flowbass.AddData(flowbass.sDetectID, "DET_ZNYGSPPY", "Detects_SJA", fLIZYPYZuoFuYuan.ToString("0"));
                flowbass.AddData(flowbass.sDetectID, "DET_ZNYGDG", "Detects_SJA", iLIDGZuoFuYuan.ToString("0"));

                flowbass.AddData(flowbass.sDetectID, "DET_ZNDJL", "Detects_SJA", bLlightfuGood ? 1 : 2);//总评
                flowbass.AddData(flowbass.sDetectID, "DET_ZNDGQJL", "Detects_SJA", bBrightfuGood ? 1 : 2);//光强
                flowbass.AddData(flowbass.sDetectID, "DET_ZNYGCZPYJL", "Detects_SJA", bFVerfuGood ? 1 : 2);//偏移
                flowbass.AddData(flowbass.sDetectID, "DET_ZNYGSPPYJL", "Detects_SJA", b远光副水平偏移判定 ? 1 : 2);//偏移
            }
            //-------------------------------------------------------------
            if (!bLlightGood)
            {
                flowbass.getbuhge(flowbass.sDetectID, "H1");
                //flowbass.updatejl(JL, flowbass.sDetectID);
            }
            else
            {

                flowbass.sethege(flowbass.sDetectID, "H1");
            }
            flowbass.AddData(flowbass.sDetectID, "DET_ZWJGCZPY", "Detects_SJA", zwjgczpy);
            flowbass.AddData(flowbass.sDetectID, "DET_ZWYGCZPY", "Detects_SJA", zwygczpy.ToString("0.00"));

            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWDGQ", "Detects_SJA", iLIGQZuoYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWYGCZPYL", "Detects_SJA", fLISXPYZuoYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWYGSPPY", "Detects_SJA", fLIZYPYZuoYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWYGDG", "Detects_SJA", iLIDGZuoYuan.ToString("0"));


            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWJGCZPYL", "Detects_SJA", fLISXPYZuoJing.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWJGSPPY", "Detects_SJA", fLIZYPYZuoJing.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_ZWJGDG", "Detects_SJA", iLIDGZuoJing.ToString("0"));





            flowbass.LedWrite(string.Format("左光强{0}", iLIGQZuoYuan), string.Format("{0}", bBrightGood ? "合格" : "不合格"), 1);
            Thread.Sleep(xssj);
            //if (flowbass.bqzd && !flowbass.sjcbz.Contains("38900"))
            {
                //if (!ygpyfalse || !flowbass.bnj)
                {
                    flowbass.LedWrite(string.Format("左远光偏移"), string.Format("{0}", (bFVerGood && b远光水平偏移判定 )? "合格" : "不合格"), 1);
                    Thread.Sleep(xssj);
                }
            }
            //if (flowbass.bFYYWXX && !flowbass.sjcbz.Contains("38900"))//近光偏移
            {
                //if (!jgpyfalse || !flowbass.bnj)
                {
                    flowbass.LedWrite(string.Format("左近光偏移"), string.Format("{0}", (bNVerGood && b近光水平偏移判定) ? "合格" : "不合格"), 1);
                    Thread.Sleep(xssj);
                }
            }
            //远光光强
            string jielun = "";
            //if (flowbass.bnj)
            //{
            //    jielun = string.Format(@"{0},{1},{2},{3}",
            //                            "左外灯远光发光强度(cd)",
            //                            iLIGQZuoYuan,
            //                            string.Format("≥{0}", flowbass.STD_LI),
            //                            bBrightGood ? "合格" : "不合格");

            //    flowbass.AddData(flowbass.sDetectID, "PD_ZWDGQ", "PD_AJ", jielun);
            //    //远光偏移
            //    if (flowbass.bqzd && !flowbass.sjcbz.Contains("38900"))
            //    {
            //        if (!ygpyfalse)
            //        {
            //            jielun = string.Format(@"{0},{1},{2},{3}",
            //                                   "左外灯远光垂直偏移(mm/H)",
            //                                   string.Format("{0}mm/{1}H", fLISXPYZuoYuan, zwygczpy.ToString("0.00")),
            //                                   string.Format("0.80H~100mm"),
            //                                   bFVerGood ? "合格" : "不合格");

            //            flowbass.AddData(flowbass.sDetectID, "PD_ZWDYGCZPYL", "PD_AJ", jielun);
            //        }
            //    }
            //    //近光偏移
            //    if (!flowbass.sCllx.Contains("三轮"))
            //    {
            //        if (flowbass.bFYYWXX && !flowbass.sjcbz.Contains("38900"))//近光偏移
            //        {
            //            if (!jgpyfalse)//近光偏移评判
            //            {
            //                jielun = string.Format(@"{0},{1},{2},{3}",
            //                                       "左外灯近光垂直偏移(mm)",
            //                                       string.Format("{0}", fLISXPYZuoJing),
            //                                       iLIDGZuoJing > 1000 ? string.Format("-350~-100") : string.Format("-300~-50"),
            //                                       bNVerGood ? "合格" : "不合格");
            //                flowbass.AddData(flowbass.sDetectID, "PD_ZWDJGCZPYL", "PD_AJ", jielun);
            //            }
            //        }
            //    }
            //}


            ////判断是否要求副灯
            //if (flowbass.iQZDZ == 4)
            //{
            //    if (iLIGQZuoFuYuan < flowbass.STD_LI)
            //    {
            //        bBrightfuGood = false;
            //    }
            //    if (fLISXPYZuoFuYuan < flowbass.STD_LFVB || fLISXPYZuoFuYuan > flowbass.STD_LFVU)
            //    {
            //        bFVerfuGood = false;
            //    }
            //    if (bBrightfuGood && bFVerfuGood)
            //    {
            //        bLlightfuGood = true;
            //    }
            //    else
            //    {
            //        bLlightfuGood = false;
            //    }
            //    znygczpy = ((float)iLIDGZuoFuYuan + fLISXPYZuoFuYuan) / (float)iLIDGZuoFuYuan;
            //    flowbass.AddData(flowbass.sDetectID, "DET_ZNDJL", "Detects_SJA", bLlightfuGood ? 1 : 2);//总评
            //    flowbass.AddData(flowbass.sDetectID, "DET_ZNDGQJL", "Detects_SJA", bBrightfuGood ? 1 : 2);//光强
            //    flowbass.AddData(flowbass.sDetectID, "DET_ZNJGCZPYJL", "Detects_SJA", bFVerfuGood ? 1 : 2);//偏移
            //}



            flowbass.AddData(flowbass.sDetectID, "DET_ZWDJL", "Detects_SJA", bLlightGood ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_ZWDGQJL", "Detects_SJA", bBrightGood ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_ZWYGCZPYJL", "Detects_SJA", bFVerGood ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_ZWJGCZPYJL", "Detects_SJA", bNVerGood ? 1 : 2);

            flowbass.AddData(flowbass.sDetectID, "DET_ZWYGSPPYJL", "Detects_SJA", b远光水平偏移判定 ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_ZWJGSPPYJL", "Detects_SJA", b近光水平偏移判定 ? 1 : 2);

            //检测结束

            //安检数据检测数据上传

            //左主灯


            //model.安检联网.modelH1 objmodellw = new model.安检联网.modelH1();
            //objmodellw.zdg = iLIDGZuoYuan.ToString();
            //objmodellw.zwjgdg = iLIDGZuoJing.ToString();
            //objmodellw.zwygqd = iLIGQZuoYuan.ToString();
            //objmodellw.zwygqdpd = bLlightGood ? "1" : "2";
            //objmodellw.zwygszpz = fLISXPYZuoYuan.ToString();
            //objmodellw.zjgszcz = fLISXPYZuoJing.ToString();
            //objmodellw.zwygczpy = zwygczpy.ToString("0.00");
            //objmodellw.zwjgczpy = zwjgczpy.ToString("0.00");
            //objmodellw.zwygczpypd = bFVerGood ? "1" : "2";
            //objmodellw.zwjgczpypd = bNVerGood ? "1" : "2";
            //objmodellw.zwdpd = bLlightGood ? "1" : "2";//fwj20191209灯光总评


            //if (!flowbass.bqzd)//远光
            //{
            //    objmodellw.zwygszpz = "";
            //    objmodellw.zwygczpy = "";
            //    objmodellw.zwygczpypd = "";
            //}
            //else
            //{
            //    if (ygpyfalse)
            //    {
            //        if (!needpy)
            //        {
            //            objmodellw.zwygszpz = "";
            //            objmodellw.zwygczpy = "";
            //        }
            //        objmodellw.zwygczpypd = "";
            //    }
            //}
            //if (!flowbass.bFYYWXX)//近光
            //{
            //    //if ()//近光偏移评判
            //    objmodellw.zjgszcz = "";
            //    objmodellw.zwjgczpy = "";
            //    objmodellw.zwjgczpypd = "";

            //}
            //else
            //{
            //    if (jgpyfalse)
            //    {
            //        if (!needpy)
            //        {
            //            objmodellw.zjgszcz = "";
            //            objmodellw.zwjgczpy = "";
            //        }
            //        objmodellw.zwjgczpypd = "";
            //    }
            //}

            //if (flowbass.bsj || flowbass.bnj)
            //{
            //    revert = flowbass.objajlwbass.write(flowbass.objcarclass, objmodellw);
            //    if (!(revert.Length > 0 && revert[0].ToString() == "1"))
            //    {
            //        flowbass.LedWrite("联网失败", revert, 1); Thread.Sleep(2000);
            //    }
            //    //上传副灯数据   问题，上传副灯数据未完成
            //    Thread.Sleep(1000);

            //    //if (sdengguangkaowei.Contains("左"))
            //    //if (sdengguangkaowei.Contains("右"))
            //    //if (sdengguangkaowei.Contains("右") && flowbass.iITERAT < 2)
            //    {
            //        flowbass.RecordProcessTime(int.Parse(flowbass.sDetectID), flowbass.sPlate, flowbass.sPclass, "Lighting", DateTime.Now, flowbass.iITERAT, "结束");
            //    }
            //    revert = flowbass.objajlwbass.SendJYXMKSSJ("H1", "结束", flowbass.gwjysbbh, flowbass.ilitongdao.ToString(), flowbass.objcarclass);
            //    if (!(revert.Length > 0 && revert[0].ToString() == "1"))
            //    {
            //        flowbass.LedWrite("联网失败", revert, 1); Thread.Sleep(2000);
            //    }
            //}
            flowbass.getProcessfinish(flowbass.sDetectID, "H1");

        }

        public void DetectLightR()
        {
            flowbass.LedWrite("右主灯检测", "请开远光灯", 1);
            objlibass.sendLIcom(10);
            xianshineirong = string.Format(@"右主灯检测");
            xianshi();

            b调灯跳过 = false;
            objlibass.byuanguang = false;
            objlibass.byuanguangfudeng = false;
            objlibass.bjingguang = false;
            objlibass.bjcshibai = false;
            objlibass.b进入近光连续测量 = false;
            objlibass.b进入远光连续测量 = false;

            //if (flowbass.bsj || flowbass.bnj)
            //{
            //    revert = flowbass.objajlwbass.SendJYXMKSSJ("H4", "开始", flowbass.gwjysbbh, flowbass.ilitongdao.ToString(), flowbass.objcarclass);
            //    if (!(revert.Length > 0 && revert[0].ToString() == "1"))
            //    {
            //        flowbass.LedWrite("联网失败", revert, 1); Thread.Sleep(2000);
            //    }
            //    flowbass.RecordProcessTime(int.Parse(flowbass.sDetectID), flowbass.sPlate, flowbass.sPclass, "Lighting", DateTime.Now, flowbass.iITERAT, "开始");
            //}

            DateTime ddglc = DateTime.Now;

            while (true)
            {
                //Thread.Sleep(10);
                if (flowbass.IsCancle())
                {
                    return;
                }
                Thread.Sleep(10);
                if (objlibass.b进入远光连续测量)//结束触发
                {
                    break;
                }
                if (objlibass.bjcshibai)
                {
                    flowbass.LedWrite("右灯寻不到光", "右灯结束", 1);
                    xianshineirong = string.Format(@"右灯寻不到光");
                    xianshi();
                    return;
                }
            }
            flowbass.LedWrite("右主灯检测", "进入远光调整", 1);
            xianshineirong = string.Format(@"进入远光调整");
            xianshi();
            //if (sdengxing.Contains("远"))// 远光部分
            {
                while (true)
                {

                    if (flowbass.IsCancle())
                    {
                        objlibass.sendLIcom(13);//仪器归位
                        return;
                    }
                    Thread.Sleep(10);
                    iLIGQYouYuan = objlibass.iLIGQ;//光强
                    fLIZYPYYouYuan = objlibass.fLIZYPY;//左右偏移
                    fLISXPYYouYuan = objlibass.fLISXPY;//上下偏移
                    iLIDGYouYuan = objlibass.iLIDG;//灯高

                    if (objlibass.byuanguang)//结束触发
                    {
                        flowbass.LedWrite("右主灯检测", "远光检测完成", 1);
                        xianshineirong = string.Format(@"右主灯检测完成");
                        xianshi();
                        break;
                    }
                    if (b调灯跳过)
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("左灯寻不到光", "左灯结束", 1);
                        xianshineirong = string.Format(@"左灯寻不到光");
                        xianshi();
                        return;
                    }
                }
            }
            b调灯跳过 = false;

            Thread.Sleep(5000);
            /////副灯
            if (flowbass.iQZDZ == 4)
            {
                objlibass.byuanguang = false;
                objlibass.b进入远光连续测量 = false;
                objlibass.bjcshibai = false;
                while (true)
                {
                    //Thread.Sleep(10);
                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                    Thread.Sleep(10);
                    if (objlibass.b进入远光连续测量)//结束触发
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("右副灯寻不到光", "右副灯结束", 1);
                        xianshineirong = string.Format(@"右副灯寻不到光");
                        xianshi();
                        return;
                    }
                }
                flowbass.LedWrite("右副灯检测", "进入远光调整", 1);
                xianshineirong = string.Format(@"进入远光调整");
                xianshi();
                //if (sdengxing.Contains("远"))// 远光部分
                {
                    while (true)
                    {
                        Thread.Sleep(10);
                        if (flowbass.IsCancle())
                        {
                            return;
                        }
                        Thread.Sleep(10);
                        iLIGQYouFuYuan = objlibass.iLIGQ;//光强
                        fLIZYPYYouFuYuan = objlibass.fLIZYPY;//左右偏移
                        fLISXPYYouFuYuan = objlibass.fLISXPY;//上下偏移
                        iLIDGYouFuYuan = objlibass.iLIDG;//灯高
                        if (objlibass.byuanguang)//结束触发
                        {
                            flowbass.LedWrite("右副灯检测", "远光检测完成", 1);
                            xianshineirong = string.Format(@"右副灯远光检测完成");
                            xianshi();
                            break;
                        }
                        if (b调灯跳过)
                        {
                            break;
                        }
                        if (objlibass.bjcshibai)
                        {
                            flowbass.LedWrite("右副灯寻不到光", "左副灯结束", 1);
                            xianshineirong = string.Format(@"右副灯寻不到光");
                            xianshi();
                            return;
                        }
                    }
                }
                b调灯跳过 = false;
            //    xianshineirong = string.Format(@"右副灯远光检测开远光");
            //    xianshi();
            //    flowbass.LedWrite("开始检测副灯", "请开副灯", 1);
            //    //m_mainform.flowwq.LedWrite(xianshineirong, "", 1);
            //    flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
            //    while (true)
            //    {

            //        if (flowbass.IsCancle())
            //        {
            //            return;
            //        }
            //        Thread.Sleep(10);
            //        iLIGQYouFuYuan = objlibass.iLIGQ;//光强
            //        fLIZYPYYouFuYuan = objlibass.fLIZYPY;//左右偏移
            //        fLISXPYYouFuYuan = objlibass.fLISXPY;//上下偏移
            //        iLIDGYouFuYuan = objlibass.iLIDG;//灯高


            //        if (ddglc.AddSeconds(120) < DateTime.Now)
            //            break;

            //        if (objlibass.byuanguangfudeng)//结束触发
            //        {
            //            objlibass.sjcdg = "右灯";
            //            xianshineirong = string.Format(@"右副灯检测完成");
            //            xianshi();
            //            //m_mainform.flowwq.LedWrite(xianshineirong, "", 1);
            //            flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
            //            break;
            //        }
            //        if (objlibass.bjcshibai)
            //            break;
            //    }
            }


            ///近光
            //if (sdengxing.Contains("近"))
            {
                flowbass.LedWrite("开始检测近光灯", "请开近光灯", 1);
                xianshineirong = string.Format(@"右主灯近光检测开近光");
                xianshi();
                while (true)
                {
                    Thread.Sleep(10);
                    if (objlibass.b进入近光连续测量)//结束触发
                    {
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("右灯寻不到光", "右灯结束", 1);
                        xianshineirong = string.Format(@"右灯寻不到光");
                        xianshi();
                        return;
                    }
                }
                flowbass.LedWrite("右主灯检测", "进入近光调整", 1);
                xianshineirong = string.Format(@"进入近光调整");
                xianshi();
                //--------------------------------------
                while (true)
                {

                    if (flowbass.IsCancle())
                    {
                        return;
                    }
                    Thread.Sleep(10);
                    iLIGQYouJing = objlibass.iLIGQ;//光强
                    fLIZYPYYouJing = objlibass.fLIZYPY;//左右偏移
                    fLISXPYYouJing = objlibass.fLISXPY;//上下偏移
                    iLIDGYouJing = objlibass.iLIDG;//灯高

                    //if (ddglc.AddSeconds(120) < DateTime.Now)
                    //    break;

                    if (b调灯跳过)
                    {
                        break;
                    }
                    if (objlibass.bjingguang)//结束触发
                    {
                        objlibass.sjcdg = "右灯";
                        flowbass.LedWrite("右主灯检测", "右主灯检测完成", 1);
                        xianshineirong = string.Format(@"右灯检测完成");
                        xianshi();
                        //m_mainform.flowwq.LedWrite(xianshineirong, "", 1);
                        //flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                        break;
                    }
                    if (objlibass.bjcshibai)
                    {
                        flowbass.LedWrite("右灯寻不到光", "右灯结束", 1);
                        xianshineirong = string.Format(@"右灯寻不到光");
                        xianshi();
                        return;
                    }
                }
            }
            b调灯跳过 = false;
            if (flowbass.IsCancle())
            {
                objlibass.sendLIcom(13);//仪器归位
                return;
            }

            objlibass.bqushu = false;
            objlibass.sendLIcom(12);//取右主灯数据
            DateTime datejs = DateTime.Now;
            while (true)
            {

                if (flowbass.IsCancle())
                {
                    objlibass.sendLIcom(13);//仪器归位
                    return;
                }
                Thread.Sleep(10);
                if (objlibass.bqushu)
                {
                    break;
                }
                if (datejs.AddSeconds(20) < DateTime.Now)
                {
                    flowbass.LedWrite("右主灯检测完成", "仪器取数失败", 1);
                    return;
                }
            }


            flowbass.LedWrite("右主灯取数完成", "", 1);
            Thread.Sleep(xssj);
            iLIGQYouYuan = objlibass.iLIGQ;//光强
            //if (jmxz)
            //{
            //    if (iLIGQYouYuan < gqsx && iLIGQYouYuan >= gqxx)
            //    {
            //        iLIGQYouYuan = (iLIGQYouYuan % 1000) + 15100;
            //    }
            //}
            fLIZYPYYouYuan = objlibass.fLIZYPY;//左右偏移
            fLISXPYYouYuan = objlibass.fLISXPY;//上下偏移
            iLIDGYouYuan = objlibass.iLIDG;//灯高
            iLIGQYouJing = objlibass.iLIGQ;//光强
            fLIZYPYYouJing = objlibass.fLIZYPY2;//左右偏移
            fLISXPYYouJing = objlibass.fLISXPY2;//上下偏移
            iLIDGYouJing = objlibass.iLIDG2;//灯高  

            iLIGHTGQ = iLIGQYouYuan;
            xianshizuo();


            //------------------------------------------------------------
            /////副灯
            if (flowbass.iQZDZ == 4)
            {
                objlibass.bqushu = false;
                objlibass.sendLIcom(17);//取左主灯数据
                datejs = DateTime.Now;
                while (true)
                {

                    if (flowbass.IsCancle())
                    {
                        objlibass.sendLIcom(13);//仪器归位
                        return;
                    }
                    Thread.Sleep(10);
                    if (objlibass.bqushu)
                    {
                        break;
                    }
                    if (datejs.AddSeconds(20) < DateTime.Now)
                    {
                        flowbass.LedWrite("右副灯", "仪器取数失败", 1);
                        return;
                    }
                }
                flowbass.LedWrite("右副灯取数完成", "", 1);
                Thread.Sleep(xssj);
                iLIGQYouFuYuan = objlibass.iLIGQ;//光强
                fLIZYPYYouFuYuan = objlibass.fLIZYPY;//左右偏移
                fLISXPYYouFuYuan = objlibass.fLISXPY;//上下偏移
                iLIDGYouFuYuan = objlibass.iLIDG;//灯高
            }
            //----------------------------------------------------------------
            float ywygczpy = 0;//右外远光垂直偏移

            float ywjgczpy = 0;//右外近光垂直偏移
            if (iLIDGYouYuan == 0)
            {
                ywygczpy = 0;
            }
            else
            {
                ywygczpy = ((float)iLIDGYouYuan + fLISXPYYouYuan) / (float)iLIDGYouYuan;
            }
            if (iLIDGYouJing == 0)
            {
                ywjgczpy = 0;
            }
            else
            {
                ywjgczpy = ((float)iLIDGYouJing + fLISXPYYouJing) / (float)iLIDGYouJing;
            }

            ywygczpy = (float)Math.Round(ywygczpy, 2);
            ywjgczpy = (float)Math.Round(ywjgczpy, 2);

            float ynygczpy = 0;//右内远光垂直偏移

            //保存数据



            flowbass.AddData(flowbass.sDetectID, "DET_YWJGCZPY", "Detects_SJA", ywjgczpy);
            flowbass.AddData(flowbass.sDetectID, "DET_YWYGCZPY", "Detects_SJA", ywygczpy);


            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWDGQ", "Detects_SJA", iLIGQYouYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWYGCZPYL", "Detects_SJA", fLISXPYYouYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWYGSPPY", "Detects_SJA", fLIZYPYYouYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWYGDG", "Detects_SJA", iLIDGYouYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YNDGQ", "Detects_SJA", iLIGQYouFuYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YNYGCZPYL", "Detects_SJA", fLISXPYYouFuYuan.ToString("0.0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YNYGSPPY", "Detects_SJA", fLIZYPYYouFuYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YNYGDG", "Detects_SJA", iLIDGYouFuYuan.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWJGCZPYL", "Detects_SJA", fLISXPYYouJing.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWJGSPPY", "Detects_SJA", fLIZYPYYouJing.ToString("0"));
            flowbass.AddData_Check(flowbass.sDetectID, "DET_YWJGDG", "Detects_SJA", iLIDGYouJing.ToString("0"));


            bool bLlightGood = true;
            bool bBrightGood = true;
            bool bFVerGood = true;
            bool bNVerGood = true;

            //bool bLlightGoodZJ = true;
            //bool bBrightGoodZJ = true;
            //bool bFVerGoodZJ = true;
            //bool bNVerGoodZJ = true;

            //bool bLlightfuGood = true;
            //bool bBrightfuGood = true;
            //bool bFVerfuGood = true;

            bool b远光水平偏移判定 = true;
            bool b近光水平偏移判定 = true;


            #region
            //if (flowbass.bnj)
            {
                if (iLIGQYouYuan < flowbass.STD_LI)
                {
                    bBrightGood = false;
                }
                if (ywygczpy < 0.8f || fLISXPYYouYuan > 100)
                {
                    bFVerGood = false;
                }
                if (fLISXPYYouJing < (iLIDGYouJing > 1000 ? -350 : -300) || fLISXPYYouJing > (iLIDGYouJing > 1000 ? -100 : -50))
                {
                    bNVerGood = false;
                }

                if (fLIZYPYZuoYuan > 350 || fLIZYPYZuoYuan < -350)
                {
                    b远光水平偏移判定 = false;
                }

                if (fLIZYPYZuoJing > 170 || fLIZYPYZuoJing < -350)
                {
                    b近光水平偏移判定 = false;
                }
                if (bBrightGood && bFVerGood && bNVerGood && b远光水平偏移判定 && b近光水平偏移判定)
                {
                    bLlightGood = true;
                }
                else
                {
                    bLlightGood = false;
                }
            }
            #endregion

            if (!bLlightGood)
            {
                flowbass.getbuhge(flowbass.sDetectID, "H4");
                //flowbass.updatejl(JL, flowbass.sDetectID);
            }
            else
            {

                flowbass.sethege(flowbass.sDetectID, "H4");
            }


            //-----------------------------------------------------------------------------------------------
            flowbass.LedWrite(string.Format("右光强{0}", iLIGQYouYuan), string.Format("{0}", bBrightGood ? "合格" : "不合格"), 1);
            Thread.Sleep(xssj);

            //if (flowbass.bqzd && !flowbass.sjcbz.Contains("38900"))
            {
                //if (!ygpyfalse || !flowbass.bnj)
                {
                    flowbass.LedWrite(string.Format("右远光偏移"), string.Format("{0}", (bFVerGood && b远光水平偏移判定) ? "合格" : "不合格"), 1);
                    Thread.Sleep(xssj);
                }
            }
            //if (flowbass.bFYYWXX && !flowbass.sjcbz.Contains("38900"))//近光偏移
            {
                //if (!jgpyfalse || !flowbass.bnj)//近光偏移评判
                {
                    flowbass.LedWrite(string.Format("右近光偏移"), string.Format("{0}", (bNVerGood && b近光水平偏移判定) ? "合格" : "不合格"), 1);
                    Thread.Sleep(xssj);
                }
            }

            bool bLlightfuGood = true;
            bool bBrightfuGood = true;
            bool bFVerfuGood = true;
            bool b远光副水平偏移判定 = true;
            double yfygczpy = 0;//左外远光垂直偏移

            //iLIGQYouFuYuan = objlibass.iLIGQ;//光强
            //fLIZYPYYouFuYuan = objlibass.fLIZYPY;//左右偏移
            //fLISXPYYouFuYuan = objlibass.fLISXPY;//上下偏移
            //iLIDGYouFuYuan = objlibass.iLIDG;//灯高

            if (flowbass.iQZDZ == 4)
            {
                if (iLIDGYouFuYuan == 0)
                {
                    yfygczpy = 0;
                }
                else
                {
                    yfygczpy = ((float)iLIDGYouFuYuan + fLISXPYYouFuYuan) / (float)iLIDGYouFuYuan;
                }
                yfygczpy = Math.Round(yfygczpy, 2);

                if (iLIGQYouFuYuan < flowbass.STD_LI)
                {
                    bBrightfuGood = false;
                }
                if (yfygczpy < 0.8f || fLISXPYYouFuYuan > 100)
                {
                    bFVerfuGood = false;
                }
                if (fLIZYPYYouFuYuan > 170 || fLIZYPYYouFuYuan < -350)
                {
                    b远光副水平偏移判定 = false;
                }
                if (bBrightfuGood && bFVerfuGood && b远光副水平偏移判定)
                {
                    bLlightfuGood = true;
                }
                else
                {
                    bLlightfuGood = false;
                }
                flowbass.AddData(flowbass.sDetectID, "DET_YNDGQ", "Detects_SJA", iLIGQYouFuYuan.ToString("0"));
                flowbass.AddData(flowbass.sDetectID, "DET_YNYGCZPYL", "Detects_SJA", fLISXPYYouFuYuan.ToString("0"));
                flowbass.AddData(flowbass.sDetectID, "DET_YNYGCZPY", "Detects_SJA", yfygczpy.ToString("0.00"));
                flowbass.AddData(flowbass.sDetectID, "DET_YNYGSPPY", "Detects_SJA", fLIZYPYYouFuYuan.ToString("0"));
                flowbass.AddData(flowbass.sDetectID, "DET_YNYGDG", "Detects_SJA", iLIDGYouFuYuan.ToString("0"));

                flowbass.AddData(flowbass.sDetectID, "DET_YNDJL", "Detects_SJA", bLlightfuGood ? 1 : 2);//总评
                flowbass.AddData(flowbass.sDetectID, "DET_YNDGQJL", "Detects_SJA", bBrightfuGood ? 1 : 2);//光强
                flowbass.AddData(flowbass.sDetectID, "DET_YNYGCZPYJL", "Detects_SJA", bFVerfuGood ? 1 : 2);//偏移
                flowbass.AddData(flowbass.sDetectID, "DET_YNYGSPPYJL", "Detects_SJA", b远光副水平偏移判定 ? 1 : 2);//偏移
            }
            //-------------------------------------------------------------
            //远光光强
            string jielun = "";

            ////if (flowbass.bnj)
            //{
            //    jielun = string.Format(@"{0},{1},{2},{3}",
            //                        "右外灯远光发光强度(cd)",
            //                            iLIGQYouYuan,
            //                            string.Format("≥{0}", flowbass.STD_LI),
            //                            bBrightGood ? "合格" : "不合格");

            //    flowbass.AddData(flowbass.sDetectID, "PD_YWDGQ", "PD_AJ", jielun);
            //    //远光偏移
            //    if (flowbass.bqzd && !flowbass.sjcbz.Contains("38900"))
            //    {
            //        if (!ygpyfalse)
            //        {
            //            jielun = string.Format(@"{0},{1},{2},{3}",
            //                                   "右外灯远光垂直偏移(mm/H)",
            //                                   string.Format("{0}mm/{1}H", fLISXPYYouYuan, ywygczpy.ToString("0.00")),
            //                                   string.Format("0.80H~100mm"),
            //                                   bFVerGood ? "合格" : "不合格");

            //            flowbass.AddData(flowbass.sDetectID, "PD_YWDYGCZPYL", "PD_AJ", jielun);
            //        }
            //    }
            //    //近光偏移
            //    if (!flowbass.sCllx.Contains("三轮"))
            //    {
            //        if (flowbass.bFYYWXX && !flowbass.sjcbz.Contains("38900"))//近光偏移
            //        {
            //            if (!jgpyfalse)//近光偏移评判
            //            {
            //                jielun = string.Format(@"{0},{1},{2},{3}",
            //                                       "右外灯近光垂直偏移(mm)",
            //                                       string.Format("{0}", fLISXPYYouJing),
            //                                       iLIDGZuoJing > 1000 ? string.Format("-350~-100") : string.Format("-300~-50"),
            //                                       bNVerGood ? "合格" : "不合格");
            //                flowbass.AddData(flowbass.sDetectID, "PD_YWDJGCZPYL", "PD_AJ", jielun);
            //            }
            //        }
            //    }
            //}
            //if (flowbass.bzj)
            //-------------------------------------------------------------------------------------------------


            ////判断是否要求副灯
            //if (flowbass.iQZDZ == 4)
            //{
            //    if (iLIGQYouFuYuan < flowbass.STD_LI)
            //    {
            //        bBrightfuGood = false;
            //    }
            //    if (fLISXPYYouFuYuan < flowbass.STD_LFVB || fLISXPYYouFuYuan > flowbass.STD_LFVU)
            //    {
            //        bFVerfuGood = false;
            //    }
            //    if (bBrightfuGood && bFVerfuGood)
            //    {
            //        bLlightfuGood = true;
            //    }
            //    else
            //    {
            //        bLlightfuGood = false;
            //    }
            //    ynygczpy = ((float)iLIDGYouFuYuan + fLISXPYYouFuYuan) / (float)iLIDGYouFuYuan;
            //    flowbass.AddData(flowbass.sDetectID, "DET_YNDJL", "Detects_SJA", bLlightfuGood ? 1 : 2);
            //    flowbass.AddData(flowbass.sDetectID, "DET_YNDGQJL", "Detects_SJA", bBrightfuGood ? 1 : 2);
            //    flowbass.AddData(flowbass.sDetectID, "DET_YNYGCZPYJL", "Detects_SJA", bFVerfuGood ? 1 : 2);
            //}



            flowbass.AddData(flowbass.sDetectID, "DET_YWDJL", "Detects_SJA", bLlightGood ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_YWDGQJL", "Detects_SJA", bBrightGood ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_YWYGCZPYJL", "Detects_SJA", bFVerGood ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_YWJGCZPYJL", "Detects_SJA", bNVerGood ? 1 : 2);

            flowbass.AddData(flowbass.sDetectID, "DET_YWYGSPPYJL", "Detects_SJA", b远光水平偏移判定 ? 1 : 2);
            flowbass.AddData(flowbass.sDetectID, "DET_YWJGSPPYJL", "Detects_SJA", b近光水平偏移判定 ? 1 : 2);
            //   m_mainform.objbass.objdb.InsertDB(sql);


            //检测结束

            //安检数据检测数据上传

            //右主灯


            //model.安检联网.modelH4 objmodellw = new model.安检联网.modelH4();
            //objmodellw.ydg = iLIDGYouYuan.ToString();
            //objmodellw.ywjgdg = iLIDGYouJing.ToString();
            //objmodellw.ywygqd = iLIGQYouYuan.ToString();
            //objmodellw.ywygqdpd = bLlightGood ? "1" : "2";
            //objmodellw.ywygszpz = fLISXPYYouYuan.ToString();
            //objmodellw.yjgszcz = fLISXPYYouJing.ToString();
            //objmodellw.ywygczpy = ywygczpy.ToString("0.00");
            //objmodellw.ywjgczpy = ywjgczpy.ToString("0.00");
            //objmodellw.ywygczpypd = bFVerGood ? "1" : "2";
            //objmodellw.ywjgczpypd = bNVerGood ? "1" : "2";
            //objmodellw.ywdpd = bLlightGood ? "1" : "2";//fwj201912009灯光总评

            //if (!flowbass.bqzd)//远光
            //{
            //    objmodellw.ywygszpz = "";
            //    objmodellw.ywygczpy = "";
            //    objmodellw.ywygczpypd = "";
            //}
            //else
            //{
            //    if (ygpyfalse)
            //    {
            //        if (!needpy)
            //        {
            //            objmodellw.ywygszpz = "";
            //            objmodellw.ywygczpy = "";
            //        }
            //        objmodellw.ywygczpypd = "";
            //    }
            //}
            //if (!flowbass.bFYYWXX)//近光
            //{
            //    //if ()//近光偏移评判

            //    objmodellw.yjgszcz = "";
            //    objmodellw.ywjgczpy = "";
            //    objmodellw.ywjgczpypd = "";

            //}
            //else
            //{
            //    if (jgpyfalse)
            //    {
            //        if ((!needpy))
            //        {
            //            objmodellw.yjgszcz = "";
            //            objmodellw.ywjgczpy = "";
            //        }
            //        objmodellw.ywjgczpypd = "";
            //    }
            //}

            //if (flowbass.bsj || flowbass.bnj)
            //{
            //    revert = flowbass.objajlwbass.write(flowbass.objcarclass, objmodellw);
            //    if (!(revert.Length > 0 && revert[0].ToString() == "1"))
            //    {
            //        flowbass.LedWrite("联网失败", revert, 1); Thread.Sleep(2000);
            //    }
            //    //上传副灯数据  问题 副灯数据未完成
            //    //if (sdengguangkaowei.Contains("左"))
            //    //if (sdengguangkaowei.Contains("左") && flowbass.iITERAT < 2)
            //    {
            //        flowbass.RecordProcessTime(int.Parse(flowbass.sDetectID), flowbass.sPlate, flowbass.sPclass, "Lighting", DateTime.Now, flowbass.iITERAT, "结束");
            //    }
            //    revert = flowbass.objajlwbass.SendJYXMKSSJ("H4", "结束", flowbass.gwjysbbh, flowbass.ilitongdao.ToString(), flowbass.objcarclass);
            //    if (!(revert.Length > 0 && revert[0].ToString() == "1"))
            //    {
            //        flowbass.LedWrite("联网失败", revert, 1); Thread.Sleep(2000);
            //    }
            //}
            flowbass.getProcessfinish(flowbass.sDetectID, "H4");
        }
        bool b调灯跳过 = false;
        private void 跳过调灯ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //b调灯跳过 = true;

            objlibass.sendLIcom(16);//测量左灯
        }

    }
}
